package com.example.lenovo.weiyi;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.com.ruanmeng.demon.CommonM;
import com.com.ruanmeng.demon.DanWeiList;
import com.com.ruanmeng.demon.PerMessM;
import com.com.ruanmeng.utils.CommonUtil;
import com.com.ruanmeng.utils.ExcelCreateUserAction;
import com.com.ruanmeng.utils.Params;
import com.com.ruanmeng.utils.PreferencesUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.Request;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import nohttp.CallServer;
import nohttp.CustomHttpListener;
import share.Const;
import share.HttpIP;

/**
 * 登陆后  强制补充信息
 */
public class MustSetPerMessActivity extends BaseActivity {

    @BindView(R.id.tv_must_name)
    EditText tvMustName;
    @BindView(R.id.tv_must_danwei)
    EditText tvMustDanwei;
    @BindView(R.id.tv_must_fbumen)
    EditText tvMustFbumen;
    @BindView(R.id.tv_must_sbumen)
    EditText tvMustSbumen;
    @BindView(R.id.tv_must_tbumen)
    EditText tvMustTbumen;
    @BindView(R.id.li_danwei)
    LinearLayout liDanwei;
    @BindView(R.id.list_danwei)
    ListView listDanwei;
    @BindView(R.id.view_bottom)
    View viewBottom;
    @BindView(R.id.tv_must_sg)
    EditText tvMustSg;
    @BindView(R.id.tv_must_age)
    EditText tvMustAge;
    @BindView(R.id.iv_mustset_name)
    ImageView ivMustsetName;
    @BindView(R.id.iv_mustset_dw)
    ImageView ivMustsetDw;
    @BindView(R.id.iv_mustset_fbm)
    ImageView ivMustsetFbm;
    @BindView(R.id.iv_mustset_sbm)
    ImageView ivMustsetSbm;
    @BindView(R.id.iv_mustset_tbm)
    ImageView ivMustsetTbm;
    @BindView(R.id.iv_mustset_height)
    ImageView ivMustsetHeight;
    @BindView(R.id.iv_mustset_weight)
    ImageView ivMustsetWeight;
    @BindView(R.id.view_must)
    View viewMust;
    @BindView(R.id.tv_must_reallyage)
    EditText tvMustReallyage;
    @BindView(R.id.iv_mustset_reallyage)
    ImageView ivMustsetReallyage;
    @BindView(R.id.tv_must_sex)
    TextView tvMustSex;
    @BindView(R.id.imv_lay_back)
    ImageView imvLayBack;
    @BindView(R.id.tv_lay_title)
    TextView tvLayTitle;
    @BindView(R.id.tv_lay_next)
    TextView tvLayNext;
    @BindView(R.id.tv_lay_zixun)
    TextView tvLayZixun;
    @BindView(R.id.tv_lay_add)
    TextView tvLayAdd;
    @BindView(R.id.tv_lay_save)
    TextView tvLaySave;
    @BindView(R.id.tv_lay_service)
    TextView tvLayService;
    @BindView(R.id.tv_lay_myorder)
    TextView tvLayMyorder;
    @BindView(R.id.imv_home)
    ImageView imvHome;
    @BindView(R.id.imv_collection)
    ImageView imvCollection;
    @BindView(R.id.rb_mess_per)
    RadioButton rbMessPer;
    @BindView(R.id.rb_mess_company)
    RadioButton rbMessCompany;
    @BindView(R.id.tv_must_cname)
    EditText tvMustCname;
    @BindView(R.id.iv_mustset_cname)
    ImageView ivMustsetCname;
    @BindView(R.id.tv_must_creallyage)
    EditText tvMustCreallyage;
    @BindView(R.id.iv_mustset_creallyage)
    ImageView ivMustsetCreallyage;
    @BindView(R.id.ll_my_cage)
    LinearLayout llMyCage;
    @BindView(R.id.tv_must_csex)
    TextView tvMustCsex;
    @BindView(R.id.ll_must_csex)
    LinearLayout llMustCsex;
    @BindView(R.id.tv_must_csg)
    EditText tvMustCsg;
    @BindView(R.id.iv_mustset_cheight)
    ImageView ivMustsetCheight;
    @BindView(R.id.tv_must_cage)
    EditText tvMustCage;
    @BindView(R.id.iv_mustset_cweight)
    ImageView ivMustsetCweight;
    @BindView(R.id.ll_my_age)
    LinearLayout llMyAge;
    @BindView(R.id.ll_must_sex)
    LinearLayout llMustSex;
    private String bm_str;
    private String dw_id;//选中单位id
    ArrayList<DanWeiList.RowsBean> Temp_list = new ArrayList<>();
    private DWListAdapter adapter;
    int IsNeedData = 2;
    private int IsGetData;
    private int datasex, sex;
    private LinearLayout li_mess_company, li_mess_per;
    //用户是0   单位1

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_must_set_per_newmess);
        ButterKnife.bind(this);
        ChangLayTitle("请完善个人资料");
        LayBack();
        ShowLaySave();
        init();
        getPerData();
    }

    public void init() {
        //个人资料
        li_mess_company = (LinearLayout) findViewById(R.id.li_mess_company);
        li_mess_per = (LinearLayout) findViewById(R.id.li_mess_per);
        tvMustAge.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {

                if (s.toString().contains(".")) {
                    if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                        s = s.toString().subSequence(0,
                                s.toString().indexOf(".") + 3);
                        tvMustAge.setText(s);
                        tvMustAge.setSelection(s.length());
                    }
                }
                if (s.toString().trim().substring(0).equals(".")) {
                    s = "0" + s;
                    tvMustAge.setText(s);
                    tvMustAge.setSelection(2);
                }

                if (s.toString().startsWith("0")
                        && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        tvMustAge.setText(s.subSequence(0, 1));
                        tvMustAge.setSelection(1);
                        return;
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {

            }
        });

        tvMustDanwei.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (IsGetData == 1) {
                    IsGetData = 0;
                } else {
                    if (IsNeedData != 0) {
                        dw_id = "";
                        liDanwei.setVisibility(View.GONE);
                        if (s.length() > 0) {
                            getDWData();
                        }
                    } else {
                        IsNeedData = 2;//恢复到需要走onTextChanged
                    }
                }
                if (s.length() == 0) {
                    dw_id = "";
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        /*tvMustDanwei.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if(actionId== EditorInfo.IME_MASK_ACTION){

                }
                return false;
            }
        });*/
        //单位自动补全
        adapter = new DWListAdapter(Temp_list);
        listDanwei.setAdapter(adapter);
        listDanwei.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                dw_id = Temp_list.get(position).getCompanyId();
                IsNeedData = 0;//此时不用再走onTextChanged
                tvMustDanwei.setText(Temp_list.get(position).getCompName());
                liDanwei.setVisibility(View.GONE);
            }
        });
        setlistener();
    }

    public void setlistener() {
        tvMustName.addTextChangedListener(this);
        tvMustDanwei.addTextChangedListener(this);
        tvMustFbumen.addTextChangedListener(this);
        tvMustSbumen.addTextChangedListener(this);
        tvMustTbumen.addTextChangedListener(this);
        tvMustSg.addTextChangedListener(this);
        tvMustAge.addTextChangedListener(this);
        tvMustReallyage.addTextChangedListener(this);

        tvMustCname.addTextChangedListener(this);
        tvMustCage.addTextChangedListener(this);
        tvMustCreallyage.addTextChangedListener(this);
        tvMustCsex.addTextChangedListener(this);
        tvMustCsg.addTextChangedListener(this);
    }

    private void getPerData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.PerMess, Const.POST);
        mRequest.addHeader("token", PreferencesUtils.getString(MustSetPerMessActivity.this, "uid"));
        CallServer.getRequestInstance().add(MustSetPerMessActivity.this, 0, mRequest,
                new CustomHttpListener(MustSetPerMessActivity.this, true, PerMessM.class) {
                    @Override
                    public void doWork(Object data, boolean isOne) {
                        PerMessM model = ((PerMessM) data);
                        IsGetData = 1;
                        tvMustName.setText(model.getObject().getUserName());
                        tvMustCname.setText(model.getObject().getUserName());
                        tvMustDanwei.setText(model.getObject().getCompName());
                        //部门
                        tvMustFbumen.setText(model.getObject().getDeptName());
                        //年纪
                        tvMustReallyage.setText(model.getObject().getAge() + "");
                        tvMustCreallyage.setText(model.getObject().getAge() + "");
                        //年纪
                        if (model.getObject().getSex() == 1) {
                            tvMustSex.setText("男");
                            tvMustCsex.setText("男");
                            sex = 1;
                        } else {
                            tvMustSex.setText("女");
                            tvMustCsex.setText("女");
                            sex = 0;
                        }
                        //身高
                        tvMustSg.setText(model.getObject().getStature() + "cm");
                        tvMustCsg.setText(model.getObject().getStature() + "cm");
                        //体重
                        tvMustAge.setText(model.getObject().getWeight() + "kg");
                        tvMustCage.setText(model.getObject().getWeight() + "kg");
                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                    }
                }, true, true);
    }

    @Override
    public void onTextChanged(CharSequence s, int i, int i1, int i2) {
        super.onTextChanged(s, i, i1, i2);
        if (TextUtils.isEmpty(tvMustName.getText().toString())) {
            ivMustsetName.setVisibility(View.GONE);
        } else {
            ivMustsetName.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustCname.getText().toString())) {
            ivMustsetCname.setVisibility(View.GONE);
        } else {
            ivMustsetCname.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustDanwei.getText().toString())) {
            ivMustsetDw.setVisibility(View.GONE);
        } else {
            ivMustsetDw.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustFbumen.getText().toString())) {
            ivMustsetFbm.setVisibility(View.GONE);
        } else {
            ivMustsetFbm.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustSbumen.getText().toString())) {
            ivMustsetSbm.setVisibility(View.GONE);
        } else {
            ivMustsetSbm.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustTbumen.getText().toString())) {
            ivMustsetTbm.setVisibility(View.GONE);
        } else {
            ivMustsetTbm.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustSg.getText().toString())) {
            ivMustsetHeight.setVisibility(View.GONE);
        } else {
            ivMustsetHeight.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustCsg.getText().toString())) {
            ivMustsetCheight.setVisibility(View.GONE);
        } else {
            ivMustsetCheight.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustAge.getText().toString())) {
            ivMustsetWeight.setVisibility(View.GONE);
        } else {
            ivMustsetWeight.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustCage.getText().toString())) {
            ivMustsetCweight.setVisibility(View.GONE);
        } else {
            ivMustsetCweight.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustReallyage.getText().toString())) {
            ivMustsetReallyage.setVisibility(View.GONE);
        } else {
            ivMustsetReallyage.setVisibility(View.VISIBLE);
        }
        if (TextUtils.isEmpty(tvMustCreallyage.getText().toString())) {
            ivMustsetCreallyage.setVisibility(View.GONE);
        } else {
            ivMustsetCreallyage.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 单位自动补全列表
     */
    class DWListAdapter extends BaseAdapter {
        private List<DanWeiList.RowsBean> list;

        public DWListAdapter(List<DanWeiList.RowsBean> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View v, ViewGroup parent) {
            v = getLayoutInflater().inflate(R.layout.item_centertext, null);
            TextView tv_text_tilte = (TextView) v.findViewById(R.id.tv_textc_tilte);
            View view_ban = (View) v.findViewById(R.id.view_ctext_ban);
            View view_man = (View) v.findViewById(R.id.view_ctext_man);
            tv_text_tilte.setText(list.get(position).getCompName());
            if (position == Temp_list.size() - 1) {
                view_ban.setVisibility(View.GONE);
                view_man.setVisibility(View.VISIBLE);
            } else {
                view_ban.setVisibility(View.VISIBLE);
                view_man.setVisibility(View.GONE);
            }
            return v;
        }

    }

    public void doClick(View v) {
        switch (v.getId()) {
            case R.id.tv_lay_save://保存
                if (rbMessPer.isChecked() == true) {
                    if (TextUtils.isEmpty(tvMustName.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的姓名！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustReallyage.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的年纪！");
                        return;
                    }
                    if (tvMustReallyage.getText().toString().startsWith("0")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的年纪！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustSex.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请选择您的性别！");
                        return;
                    }

                    if (TextUtils.isEmpty(tvMustSg.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的身高！");
                        return;
                    }
                    if (tvMustSg.getText().toString().startsWith("0")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的身高！");
                        return;
                    }
                    //年龄在18-80之间，身高在130-220之间，体重在35-200kg之间
                    if (Integer.parseInt(tvMustSg.getText().toString()) < 130 || Integer.parseInt(tvMustSg.getText().toString()) > 220) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的身高！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustAge.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的体重！");
                        return;
                    }
                    if (tvMustAge.getText().toString().endsWith(".")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的体重！");
                        return;
                    }
                    if (tvMustAge.getText().toString().startsWith("0")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的体重！");
                        return;
                    }
                    if (tvMustAge.getText().toString().endsWith(".")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的体重！");
                        return;
                    }
                    try {
                        //年龄在18-80之间，身高在130-220之间，体重在35-200kg之间
                        if (Double.parseDouble(tvMustAge.getText().toString()) < 35 || Double.parseDouble(tvMustAge.getText().toString()) > 200) {
                            CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的体重！");
                            return;
                        }
                    } catch (Exception o) {
                    }
                } else {//单位用户
                    if (TextUtils.isEmpty(tvMustDanwei.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的单位！");
                        return;
                    }
//                    if (TextUtils.isEmpty(dw_id)) {
//                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的单位！");
//                        return;
//                    }
                    if (TextUtils.isEmpty(tvMustFbumen.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的一级部门！");
                        return;
                    }
                    //部门
                    StringBuffer buffer = new StringBuffer("");
                    buffer.append(tvMustFbumen.getText().toString());
                    if (!TextUtils.isEmpty(tvMustSbumen.getText().toString())) {
                        buffer.append("-");
                        buffer.append(tvMustSbumen.getText().toString());
                    }
                    if (!TextUtils.isEmpty(tvMustTbumen.getText().toString())) {
                        buffer.append("-");
                        buffer.append(tvMustTbumen.getText().toString());
                    }
                    bm_str = buffer.toString();
                    if (TextUtils.isEmpty(tvMustCname.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的姓名！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustCreallyage.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的年纪！");
                        return;
                    }
                    if (tvMustCreallyage.getText().toString().startsWith("0")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的年纪！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustCsex.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请选择您的性别！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustCsg.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的身高！");
                        return;
                    }
                    if (tvMustCsg.getText().toString().startsWith("0")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的身高！");
                        return;
                    }
                    //年龄在18-80之间，身高在130-220之间，体重在35-200kg之间
                    if (Integer.parseInt(tvMustCsg.getText().toString()) < 130 || Integer.parseInt(tvMustCsg.getText().toString()) > 220) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的身高！");
                        return;
                    }
                    if (TextUtils.isEmpty(tvMustCage.getText().toString())) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入您的体重！");
                        return;
                    }
                    if (tvMustCage.getText().toString().endsWith(".")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的体重！");
                        return;
                    }
                    if (tvMustCage.getText().toString().startsWith("0")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的体重！");
                        return;
                    }
                    if (tvMustCage.getText().toString().endsWith(".")) {
                        CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的的体重！");
                        return;
                    }
                    try {
                        //年龄在18-80之间，身高在130-220之间，体重在35-200kg之间
                        if (Double.parseDouble(tvMustCage.getText().toString()) < 35 || Double.parseDouble(tvMustCage.getText().toString()) > 200) {
                            CommonUtil.showToask(MustSetPerMessActivity.this, "请输入正确的体重！");
                            return;
                        }
                    } catch (Exception o) {
                    }
                }
                getData();
                break;
            case R.id.view_bottom:
                liDanwei.setVisibility(View.GONE);
                break;
            case R.id.iv_mustset_name:
                tvMustName.setText("");
                break;
            case R.id.iv_mustset_reallyage:
                tvMustReallyage.setText("");
                break;
            case R.id.iv_mustset_cname:
                tvMustCname.setText("");
                break;
            case R.id.iv_mustset_dw:
                tvMustDanwei.setText("");
                break;
            case R.id.iv_mustset_fbm:
                tvMustFbumen.setText("");
                break;
            case R.id.iv_mustset_sbm:
                tvMustSbumen.setText("");
                break;
            case R.id.iv_mustset_tbm:
                tvMustTbumen.setText("");
                break;
            case R.id.iv_mustset_height:
                tvMustSg.setText("");
                break;
            case R.id.iv_mustset_cheight:
                tvMustCsg.setText("");
                break;
            case R.id.iv_mustset_cweight:
                tvMustCage.setText("");
                break;
            case R.id.iv_mustset_weight:
                tvMustAge.setText("");
                break;
            case R.id.iv_mustset_creallyage:
                tvMustCreallyage.setText("");
                break;
            case R.id.ll_must_sex://性别
                ShowPopSelectSex(true);
                break;
            case R.id.ll_must_csex://性别
                ShowPopSelectSex(false);
                break;

        }
    }

    /**
     * 选择性别
     */
    private void ShowPopSelectSex(final Boolean isper) {
        // 加载布局
        LayoutInflater inflater = LayoutInflater
                .from(MustSetPerMessActivity.this);
        View v = inflater.inflate(R.layout.sex_selector_pop_layout, null);
        LinearLayout ll_girl = (LinearLayout) v.findViewById(R.id.ll_girl);
        LinearLayout ll_boy = (LinearLayout) v.findViewById(R.id.ll_boy);
        LinearLayout ll_cancel_pop = (LinearLayout) v.findViewById(R.id.ll_cancel_pop);
        // 创建popupwindow对话框
        final PopupWindow pop = new PopupWindow(v, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        pop.setFocusable(true);// 必须有，因为要获得焦点进行输入
        // 设置此参数，点击外边可消失
        pop.setBackgroundDrawable(new BitmapDrawable());
        // 点击其他除了popupwindow对话框的地方就可使popupwindow对话框消失
        pop.setOutsideTouchable(true);
        if (Build.VERSION.SDK_INT >= 24) {
            int[] a = new int[2];
            viewMust.getLocationInWindow(a);
            pop.showAtLocation(getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, a[1] + viewMust.getHeight());
        } else {
            pop.showAsDropDown(viewMust);
        }
        ll_girl.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //TODO  请求成功之后设置
                sex = 0;
                if (isper == true) {
                    tvMustSex.setText("女");
                } else {
                    tvMustCsex.setText("女");
                }
                pop.dismiss();
            }
        });

        ll_boy.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                sex = 1;
                if (isper == true) {
                    tvMustSex.setText("男");
                } else {
                    tvMustCsex.setText("男");
                }
                pop.dismiss();
            }
        });
        ll_cancel_pop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop.dismiss();
            }
        });
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.rb_mess_per:
                li_mess_company.setVisibility(View.GONE);
                li_mess_per.setVisibility(View.VISIBLE);
                if ("男".equals(tvMustSex.getText().toString())) {
                    sex = 1;
                } else {
                    sex = 0;
                }
                break;
            case R.id.rb_mess_company:
                li_mess_company.setVisibility(View.VISIBLE);
                li_mess_per.setVisibility(View.GONE);
                if ("男".equals(tvMustCsex.getText().toString())) {
                    sex = 1;
                } else {
                    sex = 0;
                }
                break;
        }
    }

    /**
     * 修改个人资料
     */
    private void getData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.UpdatePerMess, Const.POST);
        mRequest.addHeader("token", PreferencesUtils.getString(MustSetPerMessActivity.this, "uid"));
        if (rbMessPer.isChecked()) {
            mRequest.add("userName", tvMustName.getText().toString());//姓名
            mRequest.add("age", tvMustReallyage.getText().toString());
            mRequest.add("weight", tvMustAge.getText().toString());
            mRequest.add("stature", tvMustSg.getText().toString());
            mRequest.add("isCompany", "0");
        } else {
            mRequest.add("companyId", dw_id);//单位
            mRequest.add("deptName", bm_str);//部门
            mRequest.add("userName", tvMustCname.getText().toString());//姓名
            mRequest.add("age", tvMustCreallyage.getText().toString());
            mRequest.add("weight", tvMustCage.getText().toString());
            mRequest.add("stature", tvMustCsg.getText().toString());
            mRequest.add("isCompany", "1");
        }
        mRequest.add("sex", sex);//1  男
        CallServer.getRequestInstance().add(MustSetPerMessActivity.this, 0, mRequest,
                new CustomHttpListener(MustSetPerMessActivity.this, true, CommonM.class) {

                    @Override
                    public void doWork(Object data, boolean isOne) {
                        CommonM model = ((CommonM) data);
                        PreferencesUtils.putInt(MustSetPerMessActivity.this, "Login", 1);//登陆标记
                        if (rbMessPer.isChecked()) {
                            PreferencesUtils.putString(MustSetPerMessActivity.this, "user_name", tvMustName.getText().toString());
                            PreferencesUtils.putString(MustSetPerMessActivity.this, "stature", tvMustSg.getText().toString());
                            PreferencesUtils.putString(MustSetPerMessActivity.this, "weight", tvMustAge.getText().toString());
                        } else {
                            PreferencesUtils.putString(MustSetPerMessActivity.this, "user_name", tvMustCname.getText().toString());
                            PreferencesUtils.putString(MustSetPerMessActivity.this, "stature", tvMustCsg.getText().toString());
                            PreferencesUtils.putString(MustSetPerMessActivity.this, "weight", tvMustCage.getText().toString());
                        }
                        PreferencesUtils.putString(MustSetPerMessActivity.this, "danwei", tvMustDanwei.getText().toString());
                        PreferencesUtils.putString(MustSetPerMessActivity.this, "bumen", bm_str);
                        PreferencesUtils.putString(MustSetPerMessActivity.this, "statues", "1");
                        PreferencesUtils.putInt(MustSetPerMessActivity.this, "Login", 1);//登陆标记
                        Params.ToSy = 1;
                        Intent in = new Intent(MustSetPerMessActivity.this, MainActivity.class);
                        startActivity(in);
                        finish();
                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                        if (!("100").equals(obj.getString("msgcode"))) {
                            CommonUtil.showToask(MustSetPerMessActivity.this, obj.getString("msg"));
                        }
                    }
                }, true, true);
    }

    /**
     * 获取单位自动提示
     */
    private void getDWData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.DWList, Const.POST);
        mRequest.add("compName", tvMustDanwei.getText().toString());//单位
        CallServer.getRequestInstance().add(MustSetPerMessActivity.this, 0, mRequest,
                new CustomHttpListener(MustSetPerMessActivity.this, true, DanWeiList.class) {

                    @Override
                    public void doWork(Object data, boolean isOne) {
                        DanWeiList model = ((DanWeiList) data);
                        Temp_list.clear();
                        Temp_list.addAll(model.getRows());
                        if (Temp_list.size() == 0) {
                            liDanwei.setVisibility(View.GONE);
                        } else {
                            liDanwei.setVisibility(View.VISIBLE);
                            adapter.notifyDataSetChanged();
                        }

                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                    }
                }, true, false);
    }
}
